package cn.xuexiyuan.kpi.mapper;

import cn.xuexiyuan.kpi.entity.PageParam;
import cn.xuexiyuan.kpi.entity.ScoreEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description:
 * @Author 左龙龙
 * @Date 20-11-27
 * @Version 1.0
 **/
@Repository
public interface ScoreMapper {

    @Insert({ "insert into tb_score(user_name, title, detail, type, value) values(#{user_name}, #{title}, #{detail}, #{type}, #{value})"})
    void insert(ScoreEntity score);

    @Delete("delete from tb_score where id = #{id}")
    int delete(ScoreEntity score);


    @Select("select * from tb_score where id = #{id} limit 1")
    ScoreEntity findOne(ScoreEntity score);

    @Select("select user_name, sum(value) as value from tb_score group by user_name order by value desc limit #{offset}, #{limit}")
    List<ScoreEntity> summary(PageParam<ScoreEntity> param);

    @Select("select count(1) from (select user_name from tb_score group by user_name) as score_group")
    int countSummary(PageParam<ScoreEntity> param);

    List<ScoreEntity> find(PageParam<ScoreEntity> param);

    int count(PageParam<ScoreEntity> param);



}
